{{template "../layout/header.html" .}}
<!-- 内容主体区域 -->
<div class="layui-btn-group demoTable">
    <a class="layui-btn" data-type="tabAdd" href='{{urlfor "PrivilegeController.Add"}}'>新增</a>
</div>

<div class="layui-form">
    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>权限名称</th>
            <th>控制器名称</th>
            <th>方法名称</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {{range .Data}}
        <tr>
            <td>{{.Id}}</td>
            <td>{{.Par_path | ShowCatLevel}}{{.Pri_name}}</td>
            <td>{{.Controller_name}}</td>
            <td>{{.Action_name}}</td>
            <td>{{.Created_at | TimeFormat}}</td>
            <!--<td>{{.Created_at}}</td>-->
            <td>
                <a href="javascript:;" my_event="edit" this_id="{{.Id}}" class="op layui-btn layui-btn-normal layui-btn-radius ">修改</a>
                <a href="javascript:;" my_event="del" this_id="{{.Id}}" class="op layui-btn  layui-btn-radius layui-btn-danger">删除</a>
                <!--<a href="del.html" >删除</a>-->
            </td>
        </tr>
        {{end}}
        </tbody>
    </table>
</div>
{{template "../layout/commonjs.html" .}}
<script>
    var $;
    layui.config({
        base : "js/"
    }).use(['layer','jquery'], function(){
        var table = layui.table;
        $ = layui.jquery;
        //刚进页面加载数据


        //监听
        $(".op").click(function(){
            var my_event = $(this).attr("my_event");
            var this_id = $(this).attr("this_id");
            var xsrftoken = $('meta[name=_xsrf]').attr('content');
            if(my_event === 'del'){

                layer.confirm('真的删除么?', function(){
                    var form_data = {'id':this_id}
                    $.ajax({
                        type: "post",
                        url:'{{urlfor "PrivilegeController.Del"}}',
                        dataType: "json",
                        data: form_data,
                        headers : {'X-Xsrftoken':xsrftoken},
                        success: function(out){
                            if (out.status == 0) {
                                layer.msg("删除成功",{icon: 1,time: 500},function () {
                                    window.location.reload()
                                })
                            } else {
                                layer.msg(out.message,{icon: 2,time: 500})
                            }
                        },
                        error: function(out){
                            layer.msg("未知错误",{icon: 2,time: 500})
                        }

                    });
                    return false;
                    //
                });


            } else if(my_event === 'edit'){
                window.location.href="/privilege/edit?id="+this_id
            }
        });

    });
</script>

{{template "../layout/footer.html" .}}